package mtt.us.client.views.fachbereich.studiengang;

import mtt.us.client.events.GetModelDataEvent;
import mtt.us.client.views.fachbereich.events.ShowStudiengangViewEvent;
import mtt.us.client.views.fachbereich.matrikel.MatrikelController;
import mtt.us.client.views.fachbereich.matrikel.MatrikelModel;
import mtt.us.client.views.fachbereich.matrikel.MatrikelView;
import mtt.us.client.views.fachbereich.matrikel.events.ShowMatrikelViewEvent;
import mtt.us.client.views.fachbereich.studiengang.editor.StudiengangEditorController;
import mtt.us.client.views.fachbereich.studiengang.editor.StudiengangEditorModel;
import mtt.us.client.views.fachbereich.studiengang.editor.StudiengangEditorView;
import mtt.us.client.views.fachbereich.studiengang.events.AddStudiengangEvent;
import mtt.us.client.views.fachbereich.studiengang.events.DeleteStudiengangEvent;
import mtt.us.client.views.fachbereich.studiengang.events.EditStudiengangEvent;
import mtt.us.client.views.fachbereich.studiengang.events.ShowMatrikelEvent;
import mtt.us.client.views.fachbereich.studiengang.events.ShowStudiengangEditorEvent;
import mtt.us.client.views.fachbereich.studiengang.events.StoreStudiengangEvent;
import mtt.us.dto.StudiengangDTO;
import mtt.us.hmvcFramework.client.hmvc.controller.GuiController;
import mtt.us.hmvcFramework.client.hmvc.events.AddViewEvent;
import hmvc4gwt.client.event.HmvcEvent;

public class StudiengangController extends GuiController {


	public void doInitImpl() {
		
		register(ShowStudiengangViewEvent.class, this);
		register(AddStudiengangEvent.class, this);
		register(DeleteStudiengangEvent.class, this);
		register(EditStudiengangEvent.class, this);
		register(EditStudiengangEvent.class, this);
		register(ShowMatrikelEvent.class, this);
		register(StoreStudiengangEvent.class, this);
	}

	public void handleEventImpl(HmvcEvent event) {
		
		if (event instanceof ShowStudiengangViewEvent) {
			
			fireLocalEvent(new GetModelDataEvent());
			fireEvent(new AddViewEvent(getView()), true, false, false);
			
		} else if (event instanceof AddStudiengangEvent) {
			
			addChildTriad(new StudiengangEditorModel(), new StudiengangEditorView(), new StudiengangEditorController());
			
			fireEvent(new ShowStudiengangEditorEvent(), false, false, true);
			
		} else if (event instanceof DeleteStudiengangEvent) {
			
			DeleteStudiengangEvent deleteStudiengangEvent = (DeleteStudiengangEvent) event;
			
			StudiengangDTO studiengang = deleteStudiengangEvent.getStudiengang();
			
			if (studiengang.deleteStudiengang()) {
				fireLocalEvent(new ShowStudiengangViewEvent());
			}
			
		} else if (event instanceof EditStudiengangEvent) {
			
			EditStudiengangEvent editStudiengangEvent = (EditStudiengangEvent) event;
			
			addChildTriad(new StudiengangEditorModel(editStudiengangEvent.getStudiengang()), new StudiengangEditorView(), new StudiengangEditorController());
			
			fireEvent(new ShowStudiengangEditorEvent(), false, false, true);
		} else if (event instanceof ShowMatrikelEvent) {
			
			ShowMatrikelEvent showMatrikelEvent = (ShowMatrikelEvent) event;
			
			addChildTriad(new MatrikelModel(showMatrikelEvent.getStudiengang()), new MatrikelView(), new MatrikelController());
			
			fireEvent(new ShowMatrikelViewEvent(), false, false, true);
		} else if (event instanceof StoreStudiengangEvent) {
			
		}
		
	}
}
